package com.lesserpand.rabbitmq.quartz.service.impl;

import com.lesserpand.rabbitmq.quartz.dao.JobAndTriggerDAO;
import com.lesserpand.rabbitmq.quartz.entity.dto.JobAndTriggerDTO;
import com.lesserpand.rabbitmq.quartz.job.HelloJob;
import com.lesserpand.rabbitmq.quartz.service.JobAndTriggerService;
import com.lesserpand.rabbitmq.quartz.utils.QuartzUtils;
import org.quartz.Job;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * @author bailuo
 * @version 2.0
 * @Description TODO
 * @Date Created in 2019/1/19 14:36
 */
@Service("jobAndTriggerService")
public class JobAndTriggerServiceImpl implements JobAndTriggerService {

    private static final Logger LOGGER = LoggerFactory.getLogger(JobAndTriggerServiceImpl.class);

    @Autowired
    private QuartzUtils quartzUtils;

    @Autowired
    private JobAndTriggerDAO jobAndTriggerDAO;

    @Override
    public List<JobAndTriggerDTO> getPageJob() {
        List<JobAndTriggerDTO> records = jobAndTriggerDAO.getJobAndTriggerDetails();
        return records;
    }

    @Override
    public JobAndTriggerDTO getPageJobmod() {
        return jobAndTriggerDAO.getJobAndTriggerDto();
    }

    @Override
    public String addJob(Job job, String jobClassName, String jobGroupName, Map<String, Object> map, String cronExpression) {
        return quartzUtils.createJob(job, jobClassName, jobGroupName, map, cronExpression);
    }

    @Override
    public void updateJob(String jobClassName, String jobGroupName, String cronExpression) {
        quartzUtils.updateJob(jobClassName, jobGroupName, cronExpression);
    }

    @Override
    public void deleteJob(String jobClassName, String jobGroupName) {
        quartzUtils.deleteJob(jobClassName, jobGroupName);
    }

    @Override
    public void pauseJob(String jobClassName, String jobGroupName) {
        quartzUtils.pauseJob(jobClassName, jobGroupName);
    }

    @Override
    public void resumejob(String jobClassName, String jobGroupName) {
        quartzUtils.resumejob(jobClassName, jobGroupName);
    }

}
